var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			hide : true
		}, {
			colkey : "name",
			name : "城市名称",
			align : 'left'
		}, {
			colkey : "level",
			name : "级别",
			width : "70px",
		}/*, {
			colkey : "resKey",
			name : "唯一KEY"
		}, {
			colkey : "resUrl",
			name : "URL地址"
		}*/,{
			colkey : "ishide",
			name : "是否隐藏",
			renderData : function(rowindex, data, rowdata, column) {
				//changan 改 16.5.9
				
				if(data=="0"){
					return "否";
					return '<span class="ishide"><em>o n</em><em class="active">o f f</em></span>'
				}else if(data=="1"){
					return "是";
					return '<span class="ishide"><em class="active">o n</em><em>o f f</em></span>'
				}
			}
		}/*, {
			colkey : "description",
			width : "100px",
			name : "描述"
		}*/ ],
		jsonUrl : rootPath + '/afdcitytree/treelists.shtml',
		checkbox : true,
		usePage : false,
		records : "treelists",
		treeGrid : {
			type:1,
			tree : true,
			name : 'name',
			id: "id",
			pid: "parentId"
		}
	});
	$("#search").on("click",function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	$(".addFun").on("click", function() {
		addFun();
	});
//	changan ... 点击  。。。
	$("#paging").on("click","#mytable tr td .ishide em", function() {
		var index = $("#mytable tr td .ishide em").index(this);
		$("#mytable tr td .ishide em").eq(index).addClass('active').siblings().removeClass('active');
	});
//	end
	$("#editFun").on("click", function() {
		cover._Body();
		editFun();
	});
	$("#delFun").on("click", function() {
		cover._Body();
		delFun();
	});
	$("#lyGridUp").on("click", function() {// 上移
		var jsonUrl=rootPath + '/afdcitytree/sortUpdate.shtml';
		grid.lyGridUp(jsonUrl);
	});
	$("#lyGridDown").on("click", function() {// 下移
		var jsonUrl=rootPath + '/afdcitytree/sortUpdate.shtml';
		grid.lyGridDown(jsonUrl);
	});
});
function editFun() {
	cover.closeAll();
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.alert("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.alert("必须选中一个");
		return;
	}
	var url = rootPath + '/afdcitytree/editUI.shtml?id=' + cbox;
	$.post(url,function(data){
		 layer.open({
			title : "编辑",
			type : 1,
			shift:3,
			area : [ "600px"],
			content : data
		});
	})
}
function addFun() {
	var url = rootPath + '/afdcitytree/addUI.shtml';
	$.post(url,function(data){
		layer.open({
			title : "新增",
			type : 1,
			area : [ "600px", "80%" ],
			content : data
		});
	})
	cover.closeAll();
}
function delFun() {
	cover.closeAll();
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.alert("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/afdcitytree/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
